//
//  CurrencyConverterTbvCell.m
//  ZITHER
//
//  Created by weixin on 2019/1/9.
//  Copyright © 2019 weixn. All rights reserved.
//

#import "CurrencyConverterTbvCell.h"

@implementation CurrencyConverterTbvCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    [self.countryIcon setCornerRadiusWithRadius:7.5 isMasks:YES];
    
}

- (void)setModel:(officialPricesModel *)model
{
    _model = model;
    
    //    self.countryIcon.image = model;
    //    self.countryTitle.text =

    switch (self.state) {
        case CurrencyConverterTbvCellNormal:
            [self setNormal];
            break;
        case CurrencyConverterTbvCellSelect:
            [self setSelect];
            break;
        default:
            break;
    }

//    self.price.text =
//    self.priceTitle.text =
    
    
}

//    countryIcon;
//    countryTitle;
//    price;
//    priceTitle;
-(void)setSelect{
    
    int priceInt = [self.model.priceForLocal intValue];
    NSNumberFormatter *moneyFormatter = [[NSNumberFormatter alloc] init];
    moneyFormatter.positiveFormat = @"###,##0";
    NSString *formatString = [moneyFormatter stringFromNumber:@(priceInt)];
    if (priceInt != 0) {
        self.price.text = [NSString stringWithFormat:@"￥%@",formatString];//公价
    }else{
        self.price.text = @"暂无";
    }
    self.icon.hidden = NO;

    self.priceTitle.text = @"CNY";
    self.countryTitle.text = [self getCountryName];
    self.countryIcon.image = [UIImage imageNamed:[self getCountryImage]];
}

-(void)setNormal{
    
    int priceInt = [self.model.price intValue];
    NSNumberFormatter *moneyFormatter = [[NSNumberFormatter alloc] init];
    moneyFormatter.positiveFormat = @"###,##0";
    NSString *formatString = [moneyFormatter stringFromNumber:@(priceInt)];
    if (priceInt != 0) {
        self.price.text = [NSString stringWithFormat:@"￥%@",formatString];//公价
    }else{
        self.price.text = @"暂无";
    }
    self.icon.hidden = YES;
    self.priceTitle.text = self.model.code;
    self.countryTitle.text = [self getCountryName];
    self.countryIcon.image = [UIImage imageNamed:[self getCountryImage]];
}


-(NSString*)getCountryName{
        if ([@"CHF" isEqualToString:self.model.code])
        return @"瑞士法郎";
        if ([@"USD" isEqualToString:self.model.code])
        return @"美元";
        if ([@"EUR" isEqualToString:self.model.code])
        return @"欧元";
        if ([@"CNY" isEqualToString:self.model.code])
        return @"人民币";
        if ([@"GBP" isEqualToString:self.model.code])
        return @"英镑";
        if ([@"HKD" isEqualToString:self.model.code])
        return @"港元";

    return @"未知国家";
}

-(NSString*)getCountryImage{
    if ([@"CHF" isEqualToString:self.model.code])
        return @"country_swiss";
    if ([@"USD" isEqualToString:self.model.code])
        return @"country_usa";
    if ([@"EUR" isEqualToString:self.model.code])
        return @"country_europe";
    if ([@"CNY" isEqualToString:self.model.code])
        return @"zhongguo";
    if ([@"GBP" isEqualToString:self.model.code])
        return @"country_english";
    if ([@"HKD" isEqualToString:self.model.code])
        return @"country_hk";
    return @"未知国家";
    
}

@end
